//
//  ZYPBHeaderDataUitl.m
//  ZYWebImage
//
//  Created by wangzhipan on 2025/4/25.
//

#import "ZYPBHeaderDataUitl.h"

@implementation ZYPBHeaderDataUitl
+ (NSData *)heartbeatData
{
    NSData *payload = [@"heartbeat" dataUsingEncoding:NSUTF8StringEncoding];
    
    struct PBDataHeader header;
    header.maxType = 10000001;
    header.minType = 0;
    header.operationId = 0;       //心跳设置为0
    header.length = (uint32_t)payload.length;
    
    NSMutableData *data = [NSMutableData dataWithBytes:&header length:sizeof(struct PBDataHeader)];
    [data appendData:payload];
    return [data copy];
}

+ (NSData *)configHeaderForData:(NSData *)payload
                            max:(uint32_t)maxType
                            min:(uint32_t)minType
                    operationId:(uint32_t)operationId
{
    struct PBDataHeader header;
    header.maxType = maxType;
    header.minType = minType;
    header.length = (uint32_t)payload.length;
    header.operationId = operationId;
    
    NSMutableData *data = [NSMutableData dataWithBytes:&header length:sizeof(struct PBDataHeader)];
    [data appendData:payload];
    return [data copy];
}
@end
